package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * 分析：
 * 实现：
 * 经验：
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1828 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1828.class.getResource("P1828.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		StringBuffer sb = new StringBuffer("");
		String line = stdin.readLine();
		while (line != null && !"0".equals(line)) {
			int N = Integer.valueOf(line.trim());
			Point[] ps = new Point[N];
			for (int i = 0; i < N; i ++) ps[i] = new Point(stdin.readLine());
			Arrays.sort(ps);
			int total = 1;
			int maxy = ps[N-1].y;
			for (int i = N-2; i > -1; i --) {
				if (ps[i].y > maxy) {
					maxy = ps[i].y;
					total ++;
				}
			}
			sb.append(total).append("\n");
			line = stdin.readLine();
		}
		System.out.println(sb);
	}

	private static class Point implements Comparable<Point> {

		int x;
		int y;
		
		public Point(String str) {
			StringTokenizer st = new StringTokenizer(str);
			this.x = Integer.valueOf(st.nextToken());
			this.y = Integer.valueOf(st.nextToken());
		}

		public int compareTo(Point o) {
			if (this.x == o.x) {
				return Integer.valueOf(this.y).compareTo(o.y);
			} else {
				return Integer.valueOf(this.x).compareTo(o.x);
			}
		}
	}
}